# -*- coding: utf-8 -*-

from StoreBilibiliData.CreateTable import metadata
from StoreBilibiliData.GatherData import gather_uploader_info, gather_video_info_for_all_uploader, \
    gather_comment_info_for_all_video, gather_dm_info_for_all_video

from sqlalchemy import create_engine
from sqlalchemy.engine.base import Engine, Connection

from datetime import datetime

'''
调用StoreBilibiliData包下的函数，抓取某一时间段内指定up主所有与疫情相关的视频信息；
'''

if __name__ == '__main__':
    program_start = datetime.now()
    data_folder = 'D:/MyResources/Web Scraping/Bilibili/'
    start_time = datetime(year=2020, month=6, day=1, hour=0, minute=0, second=0)
    end_time = datetime(year=2020, month=6, day=2, hour=23, minute=59, second=59)

    database_file_name = f'bilibili {start_time.date()} - {end_time.date()}.db'

    engine = create_engine('sqlite:///' + data_folder + database_file_name, echo=True, encoding='utf-8')  # type: Engine
    con = engine.connect()  # type: Connection

    metadata.create_all(engine)
    gather_uploader_info(con)
    gather_video_info_for_all_uploader(con, start_time=start_time, end_time=end_time)
    gather_dm_info_for_all_video(con)
    gather_comment_info_for_all_video(con)

    print(program_start)
    print(datetime.now())
